package com.sinosoft.perfect.system._unit.dataFormat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sinosoft.perfect.common.xmlService.XmlInfoBean;
import com.sinosoft.perfect.common.xmlService.XmlProducerDom4j;
import com.sinosoft.perfect.system._.po.TUnit;
import com.sinosoft.perfect.system._unit.formBean.UnitForm;

public class UnitGridDataFormat_DHX implements IUnitGridDataFormat {

	@Override
	public String dataFormatUnitGrid(List<UnitForm> unitFormList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (unitFormList != null && unitFormList.size() > 0) {
			for (int i = 0; i < unitFormList.size(); i++) {
				TUnit unit = unitFormList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(unit.getUnitId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", unit.getUnitId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(unit.getUnitId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(unit.getUnitId());
				cell2.setContent(unit.getUnitName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(unit.getUnitId());
				cell3.setContent(unit.getStatus().equals("0") ? "无效" : "有效");
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(unit.getUnitId());
				cell4.setContent(unit.getNote());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

}
